home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxlibs / sblib / ex1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-12  |  3.2 KB  |  143 lines

  1. /*Example 1.
  2.   Jouer un buffer.
  3.   Play from a buffer.
  4. */
  5.  
  6. /* Include pour C++ */
  7. #include <sys\stat.h>
  8. #include <fcntl.h>
  9. #include <io.h>
  10. #include <stdlib.h>
  11. #include <dir.h>
  12. #include <stdio.h>
  13. #include <conio.h>
  14.  
  15. /* Include pour la librairie. */
  16. /* Include for library. */
  17. #include "type.h"
  18. #include "sbdsp.h"
  19. #include "status.h"
  20.  
  21.  
  22. /*
  23.   Fonction KbHit. Verifie si une touche a ete pesee.
  24.   retourne 0 si une touche est pesee,
  25.   retourne 1 si aucune touche pesee.
  26.   --
  27.   KbHit Function. Check for a key press.
  28.   return 0 if a key pressed,
  29.   otherwise 1.
  30.  
  31. */
  32. int KbHit( void )
  33. {
  34.    int retour = 1;
  35.  
  36.    asm mov ah,1;
  37.    asm int 016h;
  38.    if( (_FLAGS & 64) == 64 )
  39.       retour = 0;
  40.  
  41.    return retour;
  42. }
  43.  
  44.  
  45. /*
  46.   Fonction PrintCardInfo. Affiche les informations contenues
  47.   dans la structure stc_CARD_INFO.
  48.   ---
  49.   PrintCardInfo functions. Display stc_CARD_INFO
  50.  
  51. */
  52. void PrintCardInfo( stc_CARD_INFO *card )
  53. {
  54.  
  55.    printf("   Card Info.");
  56.    printf("\n\r   ----------");
  57.  
  58.  
  59.    printf("\n\n\n\rCard Name:%s",card->cardName);
  60.    printf("\n\rI/O port:%x",card->ioPort);
  61.    printf("\n\rIRQ     :%u",card->irq);
  62.    printf("\n\r8 bits dma:%u",card->dmaChanel8);
  63.    if( card->dmaChanel16 != sta_NOT_DEFINED )
  64.       printf("\n\r16 bits dma:%u",card->dmaChanel16);
  65.    else
  66.       printf("\n\r16 bits dma:N/A");
  67.    printf("\n\rDSP version:%u.%u",card->dspMaj, card->dspMin);
  68.    printf("\n\rCurrent Sampling rate:%u",card->samplingRate);
  69.    printf("\n\rMinimum Sampling rate:%u",card->minSamplingRate);
  70.    printf("\n\rMaximum Sampling rate:%u",card->maxSamplingRate);
  71.    getch();
  72.  
  73.  
  74. }
  75.  
  76.  
  77. main()
  78. {
  79.    SB_DSP dsp;
  80.    int handle;
  81.    unsigned flagFin = 0;
  82.    char *buffer;
  83.  
  84.  
  85.    buffer = new char[1001];
  86.  
  87.    clrscr();
  88.    /* Ouverture du fichier raw */
  89.    /* Raw file open */
  90.    handle = open("c:rawfil.dat",O_RDONLY | O_BINARY,S_IREAD);
  91.    read(handle,buffer,1000);
  92.    close(handle);
  93.  
  94.    if( dsp.Set8BitsDma(1) == err_VALID_DMA )
  95.    {
  96.       if( dsp.SetIOPort(0x220) == err_VALID_PORT )
  97.       {
  98.      if( dsp.SetIrq(5) == err_VALID_IRQ )
  99.      {
  100.         if( dsp.InitCard() == err_INIT_DONE )
  101.         {
  102.            /* Le fichier sera jouer a 10000Hz.
  103.           -------------------------------- */
  104.  
  105.            /* Playback rate at 10000Hz.
  106.           ------------------------- */
  107.            dsp.SetSamplingRate(10000);
  108.            if( dsp.SetOutputBuffer(buffer,1000) == err_VALID_BUFFER )
  109.            {
  110.           /* Donne l'adresse du flag qui
  111.              nous indiquera la fin du playback.
  112.              ---------------------------------- */
  113.  
  114.           /* Set flag address.
  115.              ----------------- */
  116.  
  117.           dsp.SetUserFlag(&flagFin);
  118.           PrintCardInfo(dsp.GetCardInfo());
  119.  
  120.           /* On fait jouer le buffer jusqu'a la fin
  121.              ou jusqu'a ca qu'une touche soit peser.
  122.              --------------------------------------- */
  123.           dsp.Start();
  124.           while( !KbHit() && (flagFin == 0) );
  125.           dsp.Stop();
  126.            }
  127.            else
  128.           printf("Buffer invalide");
  129.         }
  130.         else
  131.            printf("Pas de carte trouve.");
  132.      }
  133.      else
  134.         printf("Invalide IRQ pour cette carte");
  135.       }
  136.       else
  137.      printf("Invalide IO port pour cette carte");
  138.    }
  139.    else
  140.       printf("Canal DMA 8 bits invalide pour cette carte");
  141.  
  142.    delete buffer;
  143. }